package com.spring.jackson.seckill.task;

import com.spring.jackson.seckill.cache.SeckillSuccessTokenCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Set;

@Component
public class GoodsTokenExpireClearTask {

    @Autowired
    private SeckillSuccessTokenCache seckillSuccessTokenCache;


    /**
     * 每隔1分钟触发一次
     */
    @Scheduled(cron = "0 0/1 * * * ? ")
    public void doClear() {
        Set<String> keys = seckillSuccessTokenCache.getAllToken();
        for (String key : keys) {
            //验证token是否过期，过期了自动释放redis库存
            seckillSuccessTokenCache.validateTokenByKey(key);
        }
    }


}
